package com.shawn.algorithm.recursion;

import java.util.Arrays;

public class FullPermutation {

	public static void permutation(int[] data) {
		permutation(data, 0);
	}

	private static void permutation(int[] data, int index) {
		if (index == data.length) {
			System.out.println(Arrays.toString(data));
		} else {
			for (int i = index; i < data.length; ++i) {
				//  交换元素
				swap(data, index, i);
				//交换后，再进行全排列算法
				permutation(data, index + 1);
				//还原成原来的数组，便于下一次的全排列
				swap(data, index, i);
			}
		}
	}

	private static void swap(int[] data, int s, int i) {
		int t = data[s];
		data[s] = data[i];
		data[i] = t;
	}

	public static void main(String[] args) {
		int[] data = new int[]{1, 2, 3, 4, 5, 6};
		permutation(data);
	}

}
